home *** CD-ROM | disk | FTP | other *** search
- /*
- ** PGP5GUI - A GUI using Magic User Interface v3.8
- **
- ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
- **
- ** This source code is released as FREEWARE - Use it for whatever you like,
- ** as long as NO financial reward is gained by you for such usage.
- **
- ** If you use any parts of the this source code for anything, give ME credit
- ** wherever credit is due, please ;-)
- */
-
- /* System */
- #include <exec/types.h>
- #include <exec/libraries.h>
-
- /* Libraries */
- #include <libraries/asl.h>
- #include <libraries/mui.h>
-
- /* Prototypes */
- #ifdef __GNUC__
- #include <proto/alib.h>
- #endif
-
- #include <proto/muimaster.h>
- #include <proto/exec.h>
- #include <clib/alib_protos.h>
- #include <proto/dos.h>
- #include <proto/asl.h>
-
- /* Ansi */
- #include <string.h>
-
- #include "PGP5GUI.h"
-
- /* Initial values for ASL file requester */
- #define MYLEFTEDGE 10
- #define MYTOPEDGE 20
- #define MYWIDTH 310
- #define MYHEIGHT 180
-
- extern struct Window *win;
- extern struct WinConfigs WinConfig;
- extern struct FileRequester *filerequester;
-
- extern char *ReadyMSG;
-
- extern char *encpath, *encfile, *encfilename;
- extern char *decpath, *decfile, *decfilename;
- extern char *sigpath, *sigfile, *sigfilename;
- extern char *addkeyspath, *addkeysfile, *addkeysfilename;
-
- extern char *cwdscratch;
- extern char *PGP_path;
- extern char *warning_str;
- extern char *yesno_str;
-
- /* Our "tags" array for the ASL file requester initialization */
- ULONG frtags[] =
- {
- ASLFR_TitleText, (ULONG) "\0",
- ASLFR_InitialDrawer, (ULONG) "\0",
- ASLFR_InitialFile, (ULONG) "\0",
- ASLFR_Window, 0,
- ASLFR_InitialHeight, MYHEIGHT,
- ASLFR_InitialWidth, MYWIDTH,
- ASLFR_InitialLeftEdge, MYLEFTEDGE,
- ASLFR_InitialTopEdge, MYTOPEDGE,
- ASLFR_DoSaveMode, FALSE,
- ASLFR_PositiveText, (ULONG)"OK",
- ASLFR_NegativeText, (ULONG)"Cancel",
- TAG_DONE
- };
-
- /*
- ** Returns:
- ** FALSE (0) if FileRequester error or user clicked Close/Cancel.
- ** TRUE (-1) if user clicked OK or double-clicked a file.
- */
- BOOL
- GetASLFileName(struct ObjApp *App, ULONG hail, ULONG pathbuff, ULONG filebuff)
- {
- BOOL result = FALSE;
-
- set(App->TX_Status, MUIA_Text_Contents, "\33cWaiting for file choice");
-
- /* Make the parent window go to sleep */
- set(App->WI_Main, MUIA_Window_Sleep, TRUE);
-
- /* Set some values for our file requester */
- frtags[1] = hail;
- frtags[3] = pathbuff;
- frtags[5] = filebuff;
- frtags[7] = (ULONG) win;
- frtags[9] = WinConfig.asl_Height;
- frtags[11] = WinConfig.asl_Width;
- frtags[13] = WinConfig.asl_LeftEdge;
- frtags[15] = WinConfig.asl_TopEdge;
-
- /* Open the ASL file requester */
- if (AslRequest(filerequester, (struct TagItem *)frtags))
- {
- if (*(filerequester->rf_File))
- {
- /*
- ** User clicked "OK" and we have a filname...
- ** Get copies of path and file names
- */
- strcpy((char *) pathbuff, filerequester->rf_Dir);
- strcpy((char *) filebuff, filerequester->rf_File);
-
- /* Set return value */
- result = TRUE;
- }
- else
- {
- /* Let the user know that no FILE was selected */
- DisplayBeep(0);
- }
- }
-
- /*
- ** User-friendly stuff...
- ** Save size and position settings of file requester for next use!
- */
- WinConfig.asl_Height = (ULONG) filerequester->fr_Height;
- WinConfig.asl_Width = (ULONG) filerequester->fr_Width;
- WinConfig.asl_LeftEdge = (ULONG) filerequester->fr_LeftEdge;
- WinConfig.asl_TopEdge = (ULONG) filerequester->fr_TopEdge;
-
- /* Make the parent window wake up */
- set(App->WI_Main, MUIA_Window_Sleep, FALSE);
-
- /* Wake up the parent window */
- set(App->WI_Main, MUIA_Window_Activate, TRUE);
-
- set(App->TX_Status, MUIA_Text_Contents, ReadyMSG);
-
- /* How d'we go? */
- return(result);
- }
-
- /*
- ** Returns:
- ** FALSE (0) if FileRequester error or user clicked Close/Cancel.
- ** TRUE (-1) if user clicked OK or double-clicked a file.
- */
- BOOL
- GetSaveASLFileName(struct ObjApp *App, char *hail, char *pathbuff, char *filebuff, char *tofile)
- {
- BOOL result = FALSE;
-
- /* Set ASL Requester tag for DoSaveMode (Save file mode) */
- frtags[17] = TRUE;
-
- tryagain:
- /* Get name of file to save key to... And save it! */
- if (GetASLFileName(App, (ULONG) hail, (ULONG) pathbuff, (ULONG) filebuff))
- {
- /*
- ** AddPart() mucks up 'pathbuff[]' by adding 'filebuff[]'
- ** to it. This prevents us keeping the last path visited
- ** as default for the next use of the ASL file requester.
- ** So, we get a copy of it instead and mess with that!
- */
- strcpy(tofile, pathbuff);
-
- if (AddPart(tofile, filebuff, 512))
- {
- BPTR lock = Lock(tofile, ACCESS_READ);
-
- /* Does file exist? */
- if (lock)
- {
- /* File exists! */
-
- /* Finished with lock */
- UnLock(lock);
-
- /* Overwrite file? */
- if (!MUI_Request(App->App, App->WI_Main, 0, warning_str, yesno_str,
- "File Exists!\nDo you want to overwrite it?")
- )
- goto tryagain; /* Oooer... A goto! */
- }
-
- result = TRUE;
- }
- }
-
- /* Set ASL Requester tag for DoSaveMode (Load file mode) */
- frtags[17] = FALSE;
-
- return(result);
- }
-
- void
- JoinNameParts(char *fullpath, char *pathbuff, char *filebuff)
- {
- strcpy(fullpath, pathbuff);
- AddPart(fullpath, filebuff, 512);
- }
-
- void
- StringToPathFile(char *fullpath, char *pathbuff, char *filebuff)
- {
- char *path;
-
- /* Set the default paths for the various ASL Requesters */
- if (*fullpath)
- {
- strcpy(cwdscratch, fullpath);
-
- /* Get the beginning of the file name */
- path = PathPart(cwdscratch);
-
- /* If we're at a directory name... */
- if (*path == '/')
- {
- /* Copy the file name - after the '/' */
- strcpy(filebuff, path+1);
- }
- else
- {
- /* Copy the file name - after the ':' */
- strcpy(filebuff, path);
- }
-
- /* Null terminate the end of the path name */
- *path = '\0';
-
- /* Copy the path name */
- strcpy(pathbuff, cwdscratch);
- }
- else
- {
- /* Use path to 'PGP:' as default */
- strcpy(pathbuff, PGP_path);
- }
- }
-
-
- void
- Get_Encrypt_Name(struct ObjApp *App)
- {
- char *enctest;
-
- /* Title for the file requester */
- char title[] = "Name Of File To Encrypt...";
-
- /* Get any previously saved path and file names */
- get(App->STR_PA_Encrypt_FROMFILE,MUIA_String_Contents,&enctest);
-
- /* Set the default paths for the various ASL Requesters */
- StringToPathFile(enctest, encpath, encfile);
-
- /* Get name of file and save it */
- if (GetASLFileName(App, (ULONG) &title, (ULONG) encpath, (ULONG) encfile))
- {
- if (*encfile)
- {
- JoinNameParts(encfilename, encpath, encfile);
- set(App->STR_PA_Encrypt_FROMFILE,MUIA_String_Contents,encfilename);
- }
- }
- }
-
- void
- Get_Decrypt_Name(struct ObjApp *App)
- {
- char *dectest;
-
- /* Title for the file requester */
- char title[] = "File To Decrypt/Verify...";
-
- /* Get any previously saved path and file names */
- get(App->STR_PA_Decrypt_TOFILE,MUIA_String_Contents,&dectest);
-
- /* Set the default paths for the various ASL Requesters */
- StringToPathFile(dectest, decpath, decfile);
-
- /* Get name of file and save it */
- if (GetASLFileName(App, (ULONG) &title, (ULONG) decpath, (ULONG) decfile))
- {
- if (*decfile)
- {
- JoinNameParts(decfilename, decpath, decfile);
- set(App->STR_PA_Decrypt_TOFILE,MUIA_String_Contents,decfilename);
- }
- }
- }
-
- void
- Get_Sign_Name(struct ObjApp *App)
- {
- char *sigtest;
-
- /* Title for the file requester */
- char title[] = "Name Of File To Sign...";
-
- /* Get any previously saved path and file names */
- get(App->STR_PA_Sign_POPFILE,MUIA_String_Contents,&sigtest);
-
- /* Set the default paths for the various ASL Requesters */
- StringToPathFile(sigtest, sigpath, sigfile);
-
- /* Get name of file and save it */
- if (GetASLFileName(App, (ULONG) &title, (ULONG) sigpath, (ULONG) sigfile))
- {
- if (*sigfile)
- {
- JoinNameParts(sigfilename, sigpath, sigfile);
- set(App->STR_PA_Sign_POPFILE,MUIA_String_Contents,sigfilename);
- }
- }
- }
-
- void
- Get_KeysAdd_Name(struct ObjApp *App)
- {
- char *addkeystest;
-
- /* Title for the file requester */
- char title[] = "Add PGP Key(s) From...";
-
- /* Get any previously saved path and file names */
- get(App->STR_PA_Keys_ADD_KEYFILE,MUIA_String_Contents,&addkeystest);
-
- /* Set the default paths for the various ASL Requesters */
- StringToPathFile(addkeystest, addkeyspath, addkeysfile);
-
- /* Get name of file and save it */
- if (GetASLFileName(App, (ULONG) &title, (ULONG) addkeyspath, (ULONG) addkeysfile))
- {
- if (*addkeysfile)
- {
- JoinNameParts(addkeysfilename, addkeyspath, addkeysfile);
- set(App->STR_PA_Keys_ADD_KEYFILE,MUIA_String_Contents,addkeysfilename);
- }
- }
- }
-